/**
 * 
 */
package com.nari.heatshare.action;

import java.math.BigDecimal;
import java.math.RoundingMode;

import org.apache.struts2.json.JSONUtil;
import org.apache.struts2.json.annotations.JSON;

import com.nari.coreframe.action.struts2.JSONActionSupport;
import com.nari.heatshare.model.IHeatMeterTypeParamDict;
import com.nari.heatshare.service.IHeatMeterTypeParamDictService;
import com.nari.platform.model.PageCond;
import com.nari.platform.model.ResponseMsg;
import com.nari.platform.model.ResultWithPageCond;
import com.opensymphony.xwork2.Action;

/**
 * 
 * @author Xiaopeng
 * @date 2014-6-23
 */
public class HeatMeterTypeParamDictAction extends JSONActionSupport {
	private static final long serialVersionUID = 2478924619718162532L;
	private IHeatMeterTypeParamDictService iHeatMeterTypeParamDictService;
	//热量表型号参数查询
	private String typeCode;
	//分页查询
	private int pageIndex = 1; //默认查询第一页列表
	private PageCond pageCond;
	private int pageSize;
	private ResultWithPageCond<IHeatMeterTypeParamDict> typeParamPage;
	//型号参数信息管理
	private String typeParamUID;
	private IHeatMeterTypeParamDict typeParam;
	
	/**
	 * 分页查询热表型号参数配置列表
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-6-23
	 */
	public String queryMeterTypeParamPage() throws Exception {
		//分页信息
		this.pageCond = new PageCond();
		int start = (this.pageIndex - 1) * this.pageCond.getLimit();
		this.pageCond.setStart(start);
		//分页结果
		this.typeParamPage = this.iHeatMeterTypeParamDictService.queryTypeParamPage(typeCode, pageCond);
		//计算结果集的页数
		this.pageSize = new BigDecimal(this.typeParamPage.getPageCond().getTotal())
				.divide(new BigDecimal(this.typeParamPage.getPageCond().getLimit()), RoundingMode.UP).intValue();
		if(pageSize == 0) pageSize = 1;
		return "typeParamPage";
	}
	
	/**
	 * 热量表型号参数信息管理
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-6-23
	 */
	public String queryTypeParamForManage() throws Exception {
		if(typeParamUID!=null && !"".equals(typeParamUID)) {
			this.typeParam = iHeatMeterTypeParamDictService.queryEntityById(typeParamUID);
		}
		return "typeParamManage";
	}
	
	/**
	 * 新增或修改型号参数配置
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-6-23
	 */
	public String saveOrUpdateTypeParamDict() throws Exception {
		this.rmsg = iHeatMeterTypeParamDictService.saveOrUpdateTypeParamDict(typeParam);
		this.writeJsonStrToResponse(JSONUtil.serialize(rmsg));
		return Action.SUCCESS;
	}
	
	/**
	 * 查询热量表型号参数的详细资料
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-6-23
	 */
	public String queryTypeParamDetail() throws Exception {
		if(typeParamUID!=null && !"".equals(typeParamUID)) {
			this.typeParam = iHeatMeterTypeParamDictService.queryEntityById(typeParamUID);
		}
		return "typeParamDetail";
	}
	
	/**
	 * 删除型号参数信息
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-6-24
	 */
	public String deleteTypeParamDictByUID() throws Exception {
		this.rmsg = ResponseMsg.getInstance(true, "");
		if(typeParamUID!=null && !"".equals(typeParamUID)) {
			this.iHeatMeterTypeParamDictService.deleteEntityById(typeParamUID);
		} else {
			this.rmsg = ResponseMsg.getInstance(false, "操作失败，请选择需要删除的型号参数配置！");
		}
		this.writeJsonStrToResponse(JSONUtil.serialize(rmsg));
		return Action.SUCCESS;
	}

	/**
	 * @return the iHeatMeterTypeParamDictService
	 */
	@JSON(serialize=false)
	public IHeatMeterTypeParamDictService getiHeatMeterTypeParamDictService() {
		return iHeatMeterTypeParamDictService;
	}

	/**
	 * @param iHeatMeterTypeParamDictService the iHeatMeterTypeParamDictService to set
	 */
	public void setiHeatMeterTypeParamDictService(
			IHeatMeterTypeParamDictService iHeatMeterTypeParamDictService) {
		this.iHeatMeterTypeParamDictService = iHeatMeterTypeParamDictService;
	}

	/**
	 * @return the typeCode
	 */
	public String getTypeCode() {
		return typeCode;
	}

	/**
	 * @param typeCode the typeCode to set
	 */
	public void setTypeCode(String typeCode) {
		this.typeCode = typeCode;
	}

	/**
	 * @return the pageIndex
	 */
	public int getPageIndex() {
		return pageIndex;
	}

	/**
	 * @param pageIndex the pageIndex to set
	 */
	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}

	/**
	 * @return the pageCond
	 */
	public PageCond getPageCond() {
		return pageCond;
	}

	/**
	 * @param pageCond the pageCond to set
	 */
	public void setPageCond(PageCond pageCond) {
		this.pageCond = pageCond;
	}

	/**
	 * @return the pageSize
	 */
	public int getPageSize() {
		return pageSize;
	}

	/**
	 * @param pageSize the pageSize to set
	 */
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	/**
	 * @return the typeParamPage
	 */
	public ResultWithPageCond<IHeatMeterTypeParamDict> getTypeParamPage() {
		return typeParamPage;
	}

	/**
	 * @param typeParamPage the typeParamPage to set
	 */
	public void setTypeParamPage(
			ResultWithPageCond<IHeatMeterTypeParamDict> typeParamPage) {
		this.typeParamPage = typeParamPage;
	}

	/**
	 * @return the typeParamUID
	 */
	public String getTypeParamUID() {
		return typeParamUID;
	}

	/**
	 * @param typeParamUID the typeParamUID to set
	 */
	public void setTypeParamUID(String typeParamUID) {
		this.typeParamUID = typeParamUID;
	}

	/**
	 * @return the typeParam
	 */
	public IHeatMeterTypeParamDict getTypeParam() {
		return typeParam;
	}

	/**
	 * @param typeParam the typeParam to set
	 */
	public void setTypeParam(IHeatMeterTypeParamDict typeParam) {
		this.typeParam = typeParam;
	}
	
}
